﻿Imports System.Runtime.InteropServices
Imports System.Xml
Imports System.Web
Imports CasaShowDados.DataAccess
Imports System.Collections.Generic

#Region "Imports - Excel"
Imports System.Web.UI.WebControls
Imports System.Web.UI.Page
Imports System.Drawing
#End Region

<Guid("82aa09b3-679c-4bd7-9088-740854d1612c")> _
Public Class Config
#If COM Then
    Inherits System.EnterpriseServices.ServicedComponent
#End If
    'Inherits EnterpriseServices.ServicedComponent

    'Bancos do HexaVision
    <Serializable()> Enum HVDBs
        DBVisionCorp = 0
        DBVision = 1
        DBVision_Prod = 2
        DBVision_Desv = 3
        DBVision_Simu = 4
        DBVision_Hist_Prod = 5
        DBVision_Hist_Desv = 6
        DBVision_Hist_Simu = 7
        DBVision_Os = 8
        DBVision_Integr_Prod = 12
        DBVision_Integr_Desv = 13
        DBVision_Integr_Simu = 14
        DBVision_SMF_CICS = 15
        DBVision_RDZ = 21
        DBVisionDstr = 51
        DBVisionDstr_Prod = 54
        DBVisionDstr_Desv = 53
        DBVisionDstr_Simu = 52
        DBVisionDstrHist_Prod = 57
        DBVisionDstrHist_Desv = 56
        DBVisionDstrHist_Simu = 55
        DBVision_Migracao = 100
        DBVision_Tivoli = 101
        DBVision_Gsc = 102
        DBVision_Mesu = 70
        DBServiceCenter = 200
        DBDTN = 250
        DBIR_CORP = 210
        DBVision_CDB2 = 22
        DBVISION_SLN = 30
    End Enum

    'Tipo do ADO
    <Serializable()> Enum HVTipADO
        ADONET = 1
        ADO = 2
    End Enum


    Private Shared strConn As String
    Private Shared DbMain As String
    Private Shared DbCorp As String

    'Public Shared ReadOnly Property DbName(ByVal BlnHist As Boolean) As String
    '    Get
    '        Dim httpContexto As HttpContext = HttpContext.Current
    '        If Not BlnHist Then
    '            Return httpContexto.Session("Ambiente").ToString()
    '        Else
    '            Return httpContexto.Session("Historico").ToString()
    '        End If
    '    End Get
    'End Property

    'Retorna a String de conexão apontando para o Database do Ambiente Corrente
    Public Shared ReadOnly Property Conn(ByVal SessNomCli As String, _
                                         ByVal SessAmbiente As String, _
                                         ByVal SessHistorico As String, _
                                         Optional ByVal TipADO As HVTipADO = HVTipADO.ADONET, _
                                         Optional ByVal BlnHist As Boolean = False) As String
        Get
            'Dim httpContexto As HttpContext = HttpContext.Current
            Dim obj As New Config
            Dim Servidor, dbUser, dbSenha, dbCorrente, strConn As String

            Servidor = obj.RetornaServer()
            dbUser = obj.RetornaDBUser()
            dbSenha = "root"
            If Not BlnHist Then
                dbCorrente = SessAmbiente ' httpContexto.Session("Ambiente")
            Else
                dbCorrente = SessHistorico ' httpContexto.Session("Historico")
            End If

            If TipADO = HVTipADO.ADONET Then
                strConn = "SERVER=" & Servidor & ";" & _
                          "User Id=" & dbUser & ";" & _
                          "Password=" & dbSenha & ";" & _
                          "DATABASE=" & dbCorrente & ";" & _
                          "INTEGRATED SECURITY = False;Persist Security Info = True"
            Else
                strConn = "Provider=SQLOLEDB.1; " & _
                          "Data Source=" & Servidor & ";" & _
                          "User Id=" & dbUser & ";" & _
                          "Password=" & dbSenha & ";" & _
                          "Initial Catalog=" & dbCorrente & ";" & _
                          "Persist Security Info = True"
            End If

            Return strConn
        End Get
    End Property

    'Retorna a String de Conexão apontando para o Databases passado como parâmetro
    Public Shared ReadOnly Property Conn(ByVal SessNomCli As String, _
                                         ByVal DB As HVDBs, _
                                         Optional ByVal TipADO As HVTipADO = HVTipADO.ADONET) As String
        Get
            Dim obj As New Config
            Dim Servidor, dbUser, dbSenha, DataBase, strConn As String

            Servidor = obj.RetornaServer()
            dbUser = obj.RetornaDBUser()
            dbSenha = "root"
            DataBase = Config.GetDB(DB)

            If TipADO = HVTipADO.ADONET Then
                strConn = "SERVER=" & Servidor & ";" & _
                          "User Id=" & dbUser & ";" & _
                          "Password=" & dbSenha & ";" & _
                          "DATABASE=" & DataBase & ";" & _
                          "INTEGRATED SECURITY = False;Persist Security Info = True"
            Else
                strConn = "Provider=SQLOLEDB.1; " & _
                          "Data Source=" & Servidor & ";" & _
                          "User Id=" & dbUser & ";" & _
                          "Password=" & dbSenha & ";" & _
                          "Initial Catalog=" & DataBase & ";" & _
                          "Persist Security Info = True"
            End If

            Return strConn
        End Get
    End Property
    'Retorna string de conexão para Service Center
    Public Shared ReadOnly Property ConnServCent(ByVal SessNomCli As String, _
                                     ByVal DB As HVDBs, _
                                     Optional ByVal TipADO As HVTipADO = HVTipADO.ADONET) As String
        Get
            Dim obj As New Config
            Dim Servidor, dbUser, dbSenha, DataBase, strConn As String

            Servidor = obj.RetornaServCentServ()
            dbUser = obj.RetornaServCentUsr()
            dbSenha = obj.RetornaServCentSenha()
            DataBase = Config.GetDB(DB)

            If TipADO = HVTipADO.ADONET Then
                strConn = "SERVER=" & Servidor & ";" & _
                          "User Id=" & dbUser & ";" & _
                          "Password=" & dbSenha & ";" & _
                          "DATABASE=" & DataBase & ";" & _
                          "INTEGRATED SECURITY = False;Persist Security Info = True"
            Else
                strConn = "Provider=SQLOLEDB.1; " & _
                          "Data Source=" & Servidor & ";" & _
                          "User Id=" & dbUser & ";" & _
                          "Password=" & dbSenha & ";" & _
                          "Initial Catalog=" & DataBase & ";" & _
                          "Persist Security Info = True"
            End If

            Return strConn
        End Get
    End Property

    Public Shared Property Main() As String
        Get
            Dim obj As New Config

            Return obj.RetornaMainStr()
        End Get
        Set(ByVal strValue As String)
            DbMain = strValue
        End Set
    End Property

    Public Shared Property Ambte() As String
        Get
            Dim obj As New Config

            Return obj.RetornaAmbienteLogado()
        End Get
        Set(ByVal strValue As String)
            DbMain = strValue
        End Set
    End Property

    Public Shared Property Corp() As String
        Get
            Dim obj As New Config

            Return obj.RetornaCorpStr()
        End Get
        Set(ByVal strValue As String)
            DbMain = strValue
        End Set
    End Property


    'Public Shared ReadOnly Property HistDstr() As String
    '    Get
    '        Dim httpContexto As HttpContext = HttpContext.Current
    '        Dim obj As New Config
    '        Dim retDb As String
    '        retDb = httpContexto.Session("HistoricoDstr")
    '        Return retDb
    '    End Get
    'End Property

    Private Function RetornaConnStr() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/ConnectionString")
        Return ndXML.InnerXml
    End Function

    Private Function RetornaMainStr() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/Databases/DB_VISION")
        Return ndXML.InnerXml
    End Function

    Private Function RetornaAmbienteLogado() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        docXML.Load(strArquivo)

        If Not IsNothing(docXML.SelectSingleNode("config/AmbienteLogado")) Then
            Return docXML.SelectSingleNode("config/AmbienteLogado").InnerXml
        Else
            Return Nothing
        End If

    End Function

    Private Function RetornaCorpStr() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_CORP")
        Return ndXML.InnerXml
    End Function

    Public Function RetornaServer() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)
        ndXML = docXML.SelectSingleNode("config/server")
        Return ndXML.InnerXml
    End Function

    Public Function RetornaLimiteConsFxAgencia() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)
        ndXML = docXML.SelectSingleNode("config/LimiteConsFxAgencia")
        Return ndXML.InnerXml
    End Function

    Public Function RetornaLimiteConsFlxControlMDep() As String
        Try
            Dim docXML As New XmlDocument
            'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
            Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
            Dim ndXML As XmlNode
            docXML.Load(strArquivo)
            ndXML = docXML.SelectSingleNode("config/LimiteConsFlxCtrlM")
            Return ndXML.InnerXml
        Catch ex As Exception
            Return "0"
        End Try
    End Function

    Public Function RetornaDBUser() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)
        ndXML = docXML.SelectSingleNode("config/dbUser")
        Return ndXML.InnerXml
    End Function

    Public Shared Function RetornaTotalReg() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)
        ndXML = docXML.SelectSingleNode("config/TotalRegistros")
        Return ndXML.InnerXml
    End Function

    Public Shared Function RetornaQtdElmVisioRam() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)
        ndXML = docXML.SelectSingleNode("config/QtdElmVisioRam")
        Return ndXML.InnerXml
    End Function

    Public Shared Function RetornaQtdCarga() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)
        ndXML = docXML.SelectSingleNode("config/QtdCarga")
        Return ndXML.InnerXml
    End Function

    Public Function RetornaTipPwd() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)
        ndXML = docXML.SelectSingleNode("config/TipPassword")
        Return ndXML.InnerXml
    End Function

    Public Function RetornaArqPwd() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)
        ndXML = docXML.SelectSingleNode("config/ArqPassword")
        Return ndXML.InnerXml
    End Function

    Public Function RetornaCaminhoSiteHV() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)
        ndXML = docXML.SelectSingleNode("config/HVSite")
        Return ndXML.InnerXml
    End Function

    Public Function RetornaNomeCliente() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)
        ndXML = docXML.SelectSingleNode("config/HVCliente")
        Return ndXML.InnerXml
    End Function

    Public Function RetornaFormaAcessoSite() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)
        ndXML = docXML.SelectSingleNode("config/FormaAcessoSite")
        If Not ndXML Is Nothing Then
            Return ndXML.InnerXml
        Else
            Return ""
        End If
    End Function

    Private Function RetornaDirTempBp() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/DirTempBp")
        Return ndXML.InnerXml
    End Function

    Private Function RetornaDirTempAp() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/DirTempAp")
        Return ndXML.InnerXml
    End Function

    Public Shared Function RetornaPageToRedirectOnLogout() As String

        Try

            Dim docXML As New XmlDocument

            Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString

            Dim ndXML As XmlNode

            docXML.Load(strArquivo)

            ndXML = docXML.SelectSingleNode("config/UrlToRedirectOnLogout")

            Return ndXML.InnerXml

        Catch ex As Exception

            Return String.Empty

        End Try

    End Function

    Private Function RetornaDirTempCorp() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/DirTempCorp")
        Return ndXML.InnerXml
    End Function

    Private Function RetornaDirVirtualBp() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/DirVirtualTempBp")
        Return ndXML.InnerXml
    End Function

    Private Function RetornaDirVirtualAp() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/DirVirtualTempAp")
        Return ndXML.InnerXml
    End Function

    Private Function RetornaTemplateBp() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/TemplatesBp")
        Return ndXML.InnerXml
    End Function

    Private Function RetornaTemplateAp() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/TemplatesAp")
        Return ndXML.InnerXml
    End Function

    Private Function RetornaVisioBp() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/VisioServer")
        Return ndXML.InnerXml
    End Function

    Private Function RetornaVisioAp() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/VisioServer")
        Return ndXML.InnerXml
    End Function

    Private Function RetornaDirVisioTempBp() As String
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/DirVisioTempBp")
        Return CStr(ndXML.InnerXml)
    End Function

    Private Function RetornaDirVisioTempAp() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/DirVisioTempAp")
        Return CStr(ndXML.InnerXml)
    End Function

    Public Function RetornaTraceStatus(ByVal TipTrace As Integer) As Boolean
        Dim docXML As New XmlDocument
        'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode = Nothing
        docXML.Load(strArquivo)

        Select Case TipTrace
            Case 1
                ndXML = docXML.SelectSingleNode("config/Trace/DebugViewer")
            Case 2
                ndXML = docXML.SelectSingleNode("config/Trace/EventViewer")
            Case 3
                ndXML = docXML.SelectSingleNode("config/Trace/ArqLog")
        End Select

        If Not ndXML Is Nothing Then
            If UCase(ndXML.InnerXml) = "TRUE" Then
                Return True
            Else
                Return False
            End If
        End If

    End Function

    Private Function RetornaServCentServ() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/ServiceCenter/Servidor")
        Return CStr(ndXML.InnerXml)
    End Function

    Private Function RetornaServCentBanco() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/ServiceCenter/Banco")
        Return CStr(ndXML.InnerXml)
    End Function

    Private Function RetornaServCentUsr() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/ServiceCenter/Usuario")
        Return CStr(ndXML.InnerXml)
    End Function

    Private Function RetornaServCentSenha() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/ServiceCenter/Senha")
        Return CStr(ndXML.InnerXml)
    End Function

    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' Retorna o email do suporte vision (em caso de exceções da ferramenta)
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    ''' 	[fmosca]	8/3/2007	Created
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Private Function RetornaEmailSuporte() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/Trace/SuporteMail")
        Return CStr(ndXML.InnerXml)
    End Function

    Private Function RetornaTypeImageDiagramaAlta() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/ImageDiagramaAlta")
        Return CStr(ndXML.InnerXml)
    End Function

#Region "Enum Tipo Arquivo"
    <Serializable()> Enum TipoArquivo
        Bytes = 0
        Texto = 1
    End Enum
#End Region

    Public Overloads Sub Read(ByVal Path As String, ByRef oBytes() As Byte, Optional ByVal Delete As Boolean = True)

        Dim Tam As Integer
        Dim res As Integer

        Dim oStreamReader As New System.IO.StreamReader(Path, System.Text.Encoding.Default)

        Tam = oStreamReader.BaseStream.Length

        ReDim oBytes(Tam - 1)

        res = oStreamReader.BaseStream.Read(oBytes, 0, Tam)

        oStreamReader.Close()

        If Delete Then
            System.IO.File.Delete(Path)
        End If

    End Sub

    'Retorna Database 
    Public Shared ReadOnly Property GetDB(ByVal DB As HVDBs) As String
        Get
            Dim docXML As New XmlDocument
            'Dim strArquivo As String = AppDomain.CurrentDomain.BaseDirectory & "HV.config"
            Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
            Dim ndXML As XmlNode = Nothing
            docXML.Load(strArquivo)

            Select Case DB
                Case HVDBs.DBDTN
                    ndXML = docXML.SelectSingleNode("config/Databases/DBDTN")
                Case HVDBs.DBVisionCorp
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_CORP")
                Case HVDBs.DBVision
                    ndXML = docXML.SelectSingleNode("config/Databases/DB_VISION")
                Case HVDBs.DBVision_Prod
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_PROD")
                Case HVDBs.DBVision_Desv
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_DESV")
                Case HVDBs.DBVision_Simu
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_SIMU")
                Case HVDBs.DBVision_Hist_Prod
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_HIST_PROD")
                Case HVDBs.DBVision_Hist_Desv
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_HIST_DESV")
                Case HVDBs.DBVision_Hist_Simu
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_HIST_SIMU")
                Case HVDBs.DBVision_Os
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_OS")
                Case HVDBs.DBVision_Integr_Prod
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_INTEGR_PROD")
                Case HVDBs.DBVision_Integr_Desv
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_INTEGR_DESV")
                Case HVDBs.DBVision_Integr_Simu
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_INTEGR_SIMU")
                Case HVDBs.DBVision_SMF_CICS
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_SMF_CICS")
                Case HVDBs.DBVisionDstr
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_DSTR")
                Case HVDBs.DBVisionDstr_Prod
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_DSTR_PROD")
                Case HVDBs.DBVisionDstr_Desv
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_DSTR_DESV")
                Case HVDBs.DBVisionDstr_Simu
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_DSTR_SIMU")
                Case HVDBs.DBVisionDstrHist_Prod
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_DSTR_HIST_PROD")
                Case HVDBs.DBVisionDstrHist_Desv
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_DSTR_HIST_DESV")
                Case HVDBs.DBVisionDstrHist_Simu
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_DSTR_HIST_SIMU")
                Case HVDBs.DBVision_Migracao
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_MIGRACAO")
                Case HVDBs.DBVision_Tivoli
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_TIVOLI")
                Case HVDBs.DBVision_Gsc
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_GSC")
                Case HVDBs.DBVision_Mesu
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_MESU")
                Case HVDBs.DBServiceCenter
                    ndXML = docXML.SelectSingleNode("config/ServiceCenter/Banco")
                Case HVDBs.DBIR_CORP
                    ndXML = docXML.SelectSingleNode("config/Databases/DBIR_CORP")
                Case HVDBs.DBVision_RDZ
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_RDZ")
                Case HVDBs.DBVision_CDB2
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_CDB2")
                Case HVDBs.DBVISION_SLN
                    ndXML = docXML.SelectSingleNode("config/Databases/DBVISION_SLN")
            End Select

            Return ndXML.InnerXml

        End Get
    End Property

    'Retorna a String de conexão apontando para o Database do Ambiente Corrente
    Public Shared ReadOnly Property ConnHistDstr(ByVal SessNomCli As String, ByVal SessHistoricoDstr As String, Optional ByVal TipADO As HVTipADO = HVTipADO.ADONET) As String
        Get
            'Dim httpContexto As HttpContext = HttpContext.Current
            Dim obj As New Config
            Dim Servidor, dbUser, dbSenha, dbCorrente, strConn As String

            Servidor = obj.RetornaServer()
            dbUser = obj.RetornaDBUser()
            dbSenha = "root"
            dbCorrente = SessHistoricoDstr ' httpContexto.Session("HistoricoDstr")

            If TipADO = HVTipADO.ADONET Then
                strConn = "SERVER=" & Servidor & ";" & _
                          "User Id=" & dbUser & ";" & _
                          "Password=" & dbSenha & ";" & _
                          "DATABASE=" & dbCorrente & ";" & _
                          "INTEGRATED SECURITY = False;Persist Security Info = True"
            Else
                strConn = "Provider=SQLOLEDB.1; " & _
                          "Data Source=" & Servidor & ";" & _
                          "User Id=" & dbUser & ";" & _
                          "Password=" & dbSenha & ";" & _
                          "Initial Catalog=" & dbCorrente & ";" & _
                          "Persist Security Info = True"
            End If

            Return strConn
        End Get
    End Property

    'Retorna a String de conexão apontando para o Database do Ambiente Corrente
    Public Shared ReadOnly Property ConnDstr(ByVal SessNomCli As String, ByVal SessAmbienteDstr As String, Optional ByVal TipADO As HVTipADO = HVTipADO.ADONET) As String
        Get
            'Dim httpContexto As HttpContext = HttpContext.Current
            Dim obj As New Config
            Dim Servidor, dbUser, dbSenha, dbCorrente, strConn As String

            Servidor = obj.RetornaServer()
            dbUser = obj.RetornaDBUser()
            dbSenha = "root"
            dbCorrente = SessAmbienteDstr ' httpContexto.Session("AmbienteDstr")

            If TipADO = HVTipADO.ADONET Then
                strConn = "SERVER=" & Servidor & ";" & _
                          "User Id=" & dbUser & ";" & _
                          "Password=" & dbSenha & ";" & _
                          "DATABASE=" & dbCorrente & ";" & _
                          "INTEGRATED SECURITY = False;Persist Security Info = True"
            Else
                strConn = "Provider=SQLOLEDB.1; " & _
                          "Data Source=" & Servidor & ";" & _
                          "User Id=" & dbUser & ";" & _
                          "Password=" & dbSenha & ";" & _
                          "Initial Catalog=" & dbCorrente & ";" & _
                          "Persist Security Info = True"
            End If

            Return strConn
        End Get
    End Property

    'Retorna a String de Conexão apontando para o Databases passado como parâmetro
    Public Shared ReadOnly Property ConnDstr(ByVal SessNomCli As String, _
                                         ByVal DB As HVDBs, _
                                         Optional ByVal TipADO As HVTipADO = HVTipADO.ADONET) As String
        Get
            Dim obj As New Config
            Dim Servidor, dbUser, dbSenha, DataBase, strConn As String

            Servidor = obj.RetornaServer()
            dbUser = obj.RetornaDBUser()
            dbSenha = "root"
            DataBase = Config.GetDB(DB)

            If TipADO = HVTipADO.ADONET Then
                strConn = "SERVER=" & Servidor & ";" & _
                          "User Id=" & dbUser & ";" & _
                          "Password=" & dbSenha & ";" & _
                          "DATABASE=" & DataBase & ";" & _
                          "INTEGRATED SECURITY = False;Persist Security Info = True"
            Else
                strConn = "Provider=SQLOLEDB.1; " & _
                          "Data Source=" & Servidor & ";" & _
                          "User Id=" & dbUser & ";" & _
                          "Password=" & dbSenha & ";" & _
                          "Initial Catalog=" & DataBase & ";" & _
                          "Persist Security Info = True"
            End If

            Return strConn
        End Get
    End Property

    'Retorna valor de campo string com os caracteres padrão SQL
    Public Shared ReadOnly Property FormatSQL(ByVal ValorCampo As String) As String
        Get
            Return Trim(Replace(Replace(Replace(ValorCampo, "'", "''"), "*", "%"), "?", "_"))
        End Get
    End Property


#Region "PasswordManager"
    ' Retorna nome do arquivo chave utilizado pelo Password Manager
    Private Function RetornaKeyFile() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/KeyFileName")
        Return ndXML.InnerXml
    End Function
    ' Retorna nome do arquivo de senha do Password Manager
    Private Function RetornaPwdFile() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/PwdFileName")
        Return ndXML.InnerXml
    End Function
    'Retorna ID do ambiente HexaVision para obtenção da senha via password manager
    Private Function RetornaIdAmbHv() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/IdAmbHV")
        Return ndXML.InnerXml
    End Function

#End Region


    Public ReadOnly Property GetTempBp() As String
        Get
            Return RetornaDirTempBp()
        End Get
    End Property

    Public ReadOnly Property GetTempAp() As String
        Get
            Return RetornaDirTempAp()
        End Get
    End Property

    Public ReadOnly Property GetTempCorp() As String
        Get
            Return RetornaDirTempCorp()
        End Get
    End Property

    Public ReadOnly Property GetTemplateBp() As String
        Get
            Return RetornaTemplateBp()
        End Get
    End Property

    Public ReadOnly Property GetTemplateAp() As String
        Get
            Return RetornaTemplateAp()
        End Get
    End Property

    Public ReadOnly Property GetVirtualTempBp() As String
        Get
            Return RetornaDirVirtualBp()
        End Get
    End Property

    Public ReadOnly Property GetVirtualTempAp() As String
        Get
            Return RetornaDirVirtualAp()
        End Get
    End Property

    Public ReadOnly Property GetVisioTempBp() As String
        Get
            Return RetornaDirVisioTempBp()
        End Get
    End Property

    Public ReadOnly Property GetVisioTempAp() As String
        Get
            Return RetornaDirVisioTempAp()
        End Get
    End Property

    Public ReadOnly Property GetVisioBp() As String
        Get
            Return RetornaVisioBp()
        End Get
    End Property

    Public ReadOnly Property GetVisioAp() As String
        Get
            Return RetornaVisioAp()
        End Get
    End Property

    Public ReadOnly Property GetSuporteMail() As String
        Get
            Return RetornaEmailSuporte()
        End Get
    End Property

    Public ReadOnly Property GetTypeImageDiagramaAlta() As String
        Get
            Return RetornaTypeImageDiagramaAlta()
        End Get
    End Property

    Public ReadOnly Property GetServCentServ() As String
        Get
            Return RetornaServCentServ()
        End Get
    End Property

    Public ReadOnly Property GetServCentBanco() As String
        Get
            Return RetornaServCentBanco()
        End Get
    End Property

    Public ReadOnly Property GetServCentUsr() As String
        Get
            Return RetornaServCentUsr()
        End Get
    End Property

    Public ReadOnly Property GetServCentSenha() As String
        Get
            Return RetornaServCentSenha()
        End Get
    End Property

    Public ReadOnly Property GetTempApInst() As String
        Get
            Return RetornaDirTempApInst()
        End Get
    End Property

    Public ReadOnly Property GetTempApIda() As String
        Get
            Return RetornaDirTempApIda()
        End Get
    End Property

    Public ReadOnly Property GetTemplateApInst() As String
        Get
            Return RetornaTemplateApInst()
        End Get
    End Property

    Public ReadOnly Property GetTemplateApIda() As String
        Get
            Return RetornaTemplateApIda()
        End Get
    End Property

    Private Function RetornaDirTempApInst() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/DirTempApInst")
        Return ndXML.InnerXml
    End Function

    Private Function RetornaDirTempApIda() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/DirTempApInst")
        Return ndXML.InnerXml
    End Function

    Private Function RetornaTemplateApInst() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/TemplatesApInst")
        Return ndXML.InnerXml
    End Function

    Private Function RetornaTemplateApIda() As String
        Dim docXML As New XmlDocument
        Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
        Dim ndXML As XmlNode
        docXML.Load(strArquivo)

        ndXML = docXML.SelectSingleNode("config/TemplatesIda")
        Return ndXML.InnerXml
    End Function

    Public Function RetornaDBPwdCript(ByVal Psw As String) As String
        Dim Senha As String
        Dim objActvx As Object = CreateObject("VsnComCript.clsTwofish")
        Dim Tipo As String
        Dim Tipo1 As String
        Dim Tipo2 As String
        Dim Tipo3 As String

        Tipo1 = "EASY"
        Tipo2 = "COBOL"
        Tipo3 = "NATURAL"

        Tipo = Tipo1 & Tipo2 & Tipo3
        Senha = objActvx.DecryptString(Psw, Tipo, True)
        objActvx = Nothing

        Return Senha.Trim()
    End Function


#Region "Grid Paginado - Excel"
    'Grid é montado na DownloadFile.aspx

    'Public Overloads Shared Sub ConvertExcel(ByVal ds As DataSet, ByVal response As HttpResponse)
    '    Const filename As String = "Export"
    '    ConvertExcel(ds, response, filename)
    'End Sub

    'Public Overloads Shared Sub ConvertExcel(ByVal ds As DataSet, ByVal response As HttpResponse, ByVal filename As String, Optional ByVal Origem As String = "")
    '    Dim HeaderStyle As New Style
    '    Dim ItemStyle As New Style
    '    Dim AltStyle As New Style

    '    With HeaderStyle
    '        .Font.Bold = True
    '        .BackColor = ColorTranslator.FromHtml("#000084")
    '        .ForeColor = Color.White
    '    End With

    '    With ItemStyle
    '        .Font.Bold = False
    '        .BackColor = ColorTranslator.FromHtml("#EEEEEE")
    '        .ForeColor = Color.Black
    '    End With

    '    With AltStyle
    '        .Font.Bold = False
    '        .BackColor = Color.Gainsboro
    '        .ForeColor = Color.Black
    '    End With

    '    If Origem = "CompCatDB2" Then
    '        ConvertExcelCompCatDB2(ds, response, filename, HeaderStyle, ItemStyle, AltStyle)
    '    Else
    '        ConvertExcel(ds, response, filename, HeaderStyle, ItemStyle, AltStyle)
    '    End If

    'End Sub

    'Public Overloads Shared Sub ConvertExcel(ByVal ds As DataSet, ByVal response As HttpResponse, ByVal filename As String, ByVal HeaderStyle As Style, ByVal ItemStyle As Style, ByVal AltStyle As Style)

    '    '*******************************************************************
    '    '***** Ocorre erro no download de arquivo em rede segura - SSL *****
    '    '*******************************************************************
    '    'response.Clear()
    '    'response.Charset = ""
    '    'response.ContentEncoding = System.Text.Encoding.GetEncoding("iso-8859-1")
    '    'response.ContentType = "application/vnd.ms-excel"
    '    'response.AddHeader("content-disposition", "attachment;filename=" & filename & ".xls")

    '    Dim stringWrite As New System.IO.StringWriter
    '    Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
    '    Dim dg(ds.Tables.Count - 1) As DataGrid
    '    Dim i As Integer

    '    For i = 0 To ds.Tables.Count - 1
    '        dg(i) = New DataGrid
    '        dg(i).HeaderStyle.CopyFrom(HeaderStyle)
    '        dg(i).ItemStyle.CopyFrom(ItemStyle)
    '        dg(i).AlternatingItemStyle.CopyFrom(AltStyle)
    '        dg(i).DataSource = ds.Tables(i)
    '        dg(i).DataBind()
    '        dg(i).RenderControl(htmlWrite)
    '    Next

    '    'response.Write(stringWrite.ToString)
    '    'response.End()

    '    With HttpContext.Current.Response
    '        .ClearContent()
    '        .ClearHeaders()
    '        .ContentEncoding = System.Text.Encoding.GetEncoding("iso-8859-1")
    '        .ContentType = "application/vnd.ms-excel"
    '        .AddHeader("Content-Disposition", "attachment;filename=" & filename & ".xls")
    '        .AddHeader("Pragma ", " public")
    '        .AddHeader("Cache-Control", " max-age=0")
    '        .Write(stringWrite.ToString)
    '        .End()
    '    End With

    'End Sub

    'Private Shared WithEvents dgAux As New DataGrid
    'Private Shared blnAcao As Boolean

    'Public Overloads Shared Sub ConvertExcelCompCatDB2(ByVal ds As DataSet, ByVal response As HttpResponse, ByVal filename As String, ByVal HeaderStyle As Style, ByVal ItemStyle As Style, ByVal AltStyle As Style)

    '    '*******************************************************************
    '    '***** Ocorre erro no download de arquivo em rede segura - SSL *****
    '    '*******************************************************************
    '    'response.Clear()
    '    'response.Charset = ""
    '    'response.ContentEncoding = System.Text.Encoding.GetEncoding("iso-8859-1")
    '    'response.ContentType = "application/vnd.ms-excel"
    '    'response.AddHeader("content-disposition", "attachment;filename=" & filename & ".xls")

    '    Dim stringWrite As New System.IO.StringWriter
    '    Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
    '    Dim dg(ds.Tables.Count - 1) As DataGrid
    '    Dim i As Integer

    '    For i = 0 To ds.Tables.Count - 1
    '        dgAux = New DataGrid
    '        dgAux.HeaderStyle.CopyFrom(HeaderStyle)
    '        dgAux.ItemStyle.CopyFrom(ItemStyle)
    '        dgAux.AlternatingItemStyle.CopyFrom(AltStyle)
    '        dgAux.DataSource = ds.Tables(i)
    '        blnAcao = False
    '        dgAux.DataBind()
    '        If Not ds.Tables(i).Columns.Count > 1 Then
    '            htmlWrite.Write("<br>")
    '        End If
    '        If i = ds.Tables.Count - 1 Then
    '            htmlWrite.Write("<br><br>")
    '        End If
    '        dgAux.RenderControl(htmlWrite)
    '    Next

    '    'response.Write(stringWrite.ToString)
    '    'response.End()

    '    With HttpContext.Current.Response
    '        .ClearContent()
    '        .ClearHeaders()
    '        .ContentEncoding = System.Text.Encoding.GetEncoding("iso-8859-1")
    '        .ContentType = "application/vnd.ms-excel"
    '        .AddHeader("Content-Disposition", "attachment;filename=" & filename & ".xls")
    '        .AddHeader("Pragma ", " public")
    '        .AddHeader("Cache-Control", " max-age=0")
    '        .Write(stringWrite.ToString)
    '        .End()
    '    End With

    'End Sub

    'Private Shared Sub dgAux_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgAux.ItemDataBound

    '    Dim drRow As DataRowView

    '    If e.Item.ItemType = ListItemType.Header Then
    '        For i As Integer = 0 To e.Item.Cells.Count - 1
    '            If e.Item.Cells(i).Text = "TIP_ACAO" Then
    '                e.Item.Cells(i).Visible = False
    '                blnAcao = True
    '            End If
    '        Next
    '    End If

    '    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
    '        drRow = e.Item.DataItem
    '        If blnAcao Then
    '            Select Case CStr(drRow("TIP_ACAO"))
    '                Case "A"
    '                    e.Item.Style.Item("color") = "orange"
    '                Case "N"
    '                    e.Item.Style.Item("color") = "red"
    '                Case "E"
    '                    e.Item.Style.Item("background-color") = "white"
    '                    e.Item.Style.Item("color") = "green"
    '            End Select
    '            e.Item.Cells(e.Item.Cells.Count - 1).Visible = False
    '        End If

    '    End If

    'End Sub

    Public Shared Function RemoveExcel(ByVal ds As DataSet, ByVal tab As Integer, ByVal col As Integer) As DataSet
        ds.Tables(tab).Columns.Remove(ds.Tables(tab).Columns(col))
        Return ds
    End Function

#End Region


#Region "Configuração Links Site"

    Public Enum Sites
        None = 0
        Portal = 1
        Executivo = 2
        AltaPlataforma = 3
        Administracao = 4
        Corporativo = 5
        BaixaPlataforma = 6
        DTN = 7
        Servicos = 8
        Instituconal = 9
        ExecutivoCielo = 10
        CDB2 = 11
        Idi = 12
        Ida = 13
        HPM = 14
        FTPA = 15
        PDA = 16
        ADP = 17
        PacoteJcl = 18
        HexaPortal = 99
    End Enum

    Public Enum EnumTipoLink
        Nenhum = 0
        PaginaInicial = 1
    End Enum

    Private Function ConsultaLink(ByVal nomSite As String) As String
        Try
            Dim stringConexao As String = Config.Conn(RetornaNomeCliente(), Config.HVDBs.DBVisionCorp)
            Dim ds As DataSet
            Dim sqlParam As New SqlClient.SqlParameter("@NOM_SITE", SqlDbType.VarChar)
            Dim servidor As String = String.Empty
            Dim url As String
            Dim link As String = String.Empty

            sqlParam.Value = nomSite.Trim()

            ds = SqlHelper.ExecuteDataset(stringConexao, CommandType.StoredProcedure, "PRT_STO_CONS_LINK", sqlParam)

            If ds.Tables.Count > 0 AndAlso ds.Tables(0).Rows.Count > 0 Then
                If IsDBNull(ds.Tables(0).Rows(0)("SRV")) = True Then
                    servidor = HttpContext.Current.Request.Url.Host
                End If
                url = ds.Tables(0).Rows(0)("URL_INDEX").ToString()

                link = "http://" & servidor & "/" & url

            Else
                Throw New Exception("Configuração para o Site " & nomSite & " não encontrada na tabela DBHV0000.VSN_CFG_SITE")
            End If

            Return link

        Catch ex As Exception
            Throw New Exception(ex.Message, ex)
        End Try
    End Function

#Region "Consulta Link Hexa Portal"

    Private Function ConsultaLinkHexaPortal(ByVal nomSite As String) As String
        Try
            Dim stringConexao As String = Config.Conn(RetornaNomeCliente(), Config.HVDBs.DBVisionCorp)
            Dim ds As DataSet
            Dim sqlParam As New SqlClient.SqlParameter("@NOM_SITE", SqlDbType.VarChar)
            Dim servidor As String = String.Empty
            Dim url As String
            Dim link As String = String.Empty

            sqlParam.Value = nomSite.Trim()

            ds = SqlHelper.ExecuteDataset(stringConexao, CommandType.StoredProcedure, "HP_STO_CONS_LINK", sqlParam)

            If ds.Tables.Count > 0 AndAlso ds.Tables(0).Rows.Count > 0 Then
                If IsDBNull(ds.Tables(0).Rows(0)("SRV")) = True Then
                    servidor = HttpContext.Current.Request.Url.Host
                End If
                url = ds.Tables(0).Rows(0)("URL_APPL").ToString()

                link = "http://" & servidor & "/" & url

            Else
                Throw New Exception("Configuração para o Site " & nomSite & " não encontrada na tabela DBHV0000.TB047_HEXA_PRTL")
            End If

            Return link

        Catch ex As Exception
            Throw New Exception(ex.Message, ex)
        End Try
    End Function
#End Region

    Private Function PrepararUrl(ByVal url As String) As String

        Try
            url = url.Replace("\", "/")
            Dim urlFormatada As String = url.Substring(0, url.LastIndexOf("/") + 1)
            Return urlFormatada

        Catch ex As Exception
            Throw New Exception(ex.Message, ex)
        End Try

    End Function


    Public Function RetornaLink(ByVal site As Sites, Optional ByVal tipo As EnumTipoLink = EnumTipoLink.PaginaInicial) As String
        Try
            Dim link As String = String.Empty

            Select Case site
                Case Sites.Administracao
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkAdministracao")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("Administração")
                    End If
                Case Sites.AltaPlataforma
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkAltaPlataforma")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("Alta Plataforma")
                    End If
                Case Sites.BaixaPlataforma
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkBaixaPlataforma")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("Baixa Plataforma")
                    End If
                Case Sites.Corporativo
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkCorporativo")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("Corporativo")
                    End If
                Case Sites.DTN
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkDTN")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("DTN")
                    End If
                Case Sites.Executivo
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkExecutivo")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("Executivo")
                    End If
                Case Sites.Portal
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkPortal")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("Portal")
                    End If
                Case Sites.Servicos
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkServico")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("Serviços")
                    End If
                Case Sites.Instituconal
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkInstitucional")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("Institucional")
                    End If
                Case Sites.ExecutivoCielo
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkExecutivoCielo")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("ExecutivoCielo")
                    End If
                Case Sites.CDB2
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkCDB2")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("Certificação DB2")
                    End If
                Case Sites.Idi
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkIdi")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("Indicador de Indisponibilidade")
                    End If
                Case Sites.HPM
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkHPM")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("HPM")
                    End If
                Case Sites.PDA
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkPDA")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("PDA")
                    End If
                Case Sites.ADP
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkADP")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("ADP")
                    End If
                Case Sites.PacoteJcl
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkPacoteJcl")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("Pacote de JCL")
                    End If
                Case Sites.ADP
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkADP")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("ADP")
                    End If

                Case Else
                    Return ""
            End Select

            If tipo = EnumTipoLink.Nenhum Then

                link = PrepararUrl(link)

            End If

            Return link

        Catch ex As Exception
            Throw New Exception(ex.Message, ex)
        End Try
    End Function

#Region "Retorna LinK Hexa Hexa Portal"

    Public Function RetornaLinkHexaPortal(ByVal site As Sites, Optional ByVal tipo As EnumTipoLink = EnumTipoLink.PaginaInicial) As String
        Try
            Dim link As String = String.Empty

            Select Case site
                Case Sites.Administracao
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkAdministracao")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLinkHexaPortal("Administração")
                    End If
                Case Sites.AltaPlataforma
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkAltaPlataforma")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLinkHexaPortal("Alta Plataforma")
                    End If
                Case Sites.BaixaPlataforma
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkBaixaPlataforma")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLinkHexaPortal("Baixa Plataforma")
                    End If
                Case Sites.Corporativo
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkCorporativo")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLinkHexaPortal("Corporativo")
                    End If
                Case Sites.DTN
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkDTN")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLinkHexaPortal("DTN")
                    End If
                Case Sites.Executivo
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkExecutivo")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLinkHexaPortal("Executivo")
                    End If
                Case Sites.Portal
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkPortal")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLinkHexaPortal("Portal")
                    End If
                Case Sites.Servicos
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkServico")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLinkHexaPortal("Serviços")
                    End If
                Case Sites.Instituconal
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkInstitucional")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLinkHexaPortal("Institucional")
                    End If
                Case Sites.ExecutivoCielo
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkExecutivoCielo")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLinkHexaPortal("ExecutivoCielo")
                    End If
                Case Sites.CDB2
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkCDB2")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLinkHexaPortal("Certificação DB2")
                    End If
                Case Sites.HexaPortal
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkHexaPortal")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("Hexa Portal")
                    End If
                Case Sites.Idi
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkIdi")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("Indicador de Indisponibilidade")
                    End If
                Case Sites.Ida
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkIda")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLinkHexaPortal("Sustentação de Ambiente")
                    End If
                Case Sites.HPM
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linHPM")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("HPM")
                    End If
                Case Sites.FTPA
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkFTPA")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("FTPA")
                    End If
                Case Sites.PDA
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkPDA")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("PDA")
                    End If
                Case Sites.PacoteJcl
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkPacoteJcl")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("Pacote de JCL")
                    End If
                Case Sites.ADP
                    link = System.Configuration.ConfigurationManager.AppSettings.Item("linkADP")
                    If String.IsNullOrEmpty(link) Then
                        link = ConsultaLink("ADP")
                    End If
                Case Else

                    Return ""
            End Select

            If tipo = EnumTipoLink.Nenhum Then

                link = PrepararUrl(link)

            End If

            Return link

        Catch ex As Exception
            Throw New Exception(ex.Message, ex)
        End Try
    End Function
#End Region

    Public Function RetornaLinkIR() As String
        Try

            Dim link As String = String.Empty

            link = ConsultaLink("Executivo")

            Return link

        Catch ex As Exception
            Throw New Exception(ex.Message, ex)
        End Try
    End Function

    'Public Function RetornaLinkPortal() As String
    '    Try

    '        Dim link As String = String.Empty

    '        link = ConsultaLink("Portal")

    '        Return link

    '    Catch ex As Exception
    '        Throw New Exception(ex.Message, ex)
    '    End Try
    'End Function

    Public Function RetornaLinkAltaPlataforma() As String
        Try

            Dim link As String = String.Empty

            link = ConsultaLink("Alta Plataforma")

            Return link

        Catch ex As Exception
            Throw New Exception(ex.Message, ex)
        End Try
    End Function

    Public Function RetornaLinkAdministracao() As String
        Try

            Dim link As String = String.Empty

            link = ConsultaLink("Administração")

            Return link

        Catch ex As Exception
            Throw New Exception(ex.Message, ex)
        End Try
    End Function

    Public Function RetornaLinkCorporativo() As String
        Try

            Dim link As String = String.Empty

            link = ConsultaLink("Corporativo")

            Return link

        Catch ex As Exception
            Throw New Exception(ex.Message, ex)
        End Try
    End Function

    Public Function RetornaLinkBaixaPlataforma() As String
        Try

            Dim link As String = String.Empty

            link = ConsultaLink("Baixa Plataforma")

            Return link

        Catch ex As Exception
            Throw New Exception(ex.Message, ex)
        End Try
    End Function

    Public Function RetornaLinkDTN() As String
        Try

            Dim link As String = String.Empty

            link = ConsultaLink("DTN")

            Return link

        Catch ex As Exception
            Throw New Exception(ex.Message, ex)
        End Try
    End Function

    Public Function RetornaLinkServicos() As String
        Try

            Dim link As String = String.Empty

            link = ConsultaLink("Serviços")
            Return link

        Catch ex As Exception
            Throw New Exception(ex.Message, ex)
        End Try
    End Function


#End Region

    Public Function retornaSrvIR() As String
        Try
            'RetornaLinkIR()

            Return System.Configuration.ConfigurationManager.AppSettings.Item("SRV_IR")
        Catch ex As Exception
            Throw New Exception(ex.Message, ex)
        End Try
    End Function

    Public Function retornaSrvPortal() As String
        Try
            Return System.Configuration.ConfigurationManager.AppSettings.Item("SRV_PORTAL")
        Catch ex As Exception
            Throw New Exception(ex.Message, ex)
        End Try
    End Function

    Public Function retornaLinkPortal() As String
        Try
            Return System.Configuration.ConfigurationManager.AppSettings.Item("LINK_PORTAL")
        Catch ex As Exception
            Throw New Exception(ex.Message, ex)
        End Try
    End Function

    Public Function retornaVersao() As String
        Dim strVersao As String
        Dim stringConexao As String = Conn(RetornaNomeCliente(), HVDBs.DBVisionCorp)
        strVersao = SqlHelper.ExecuteScalar(stringConexao, "PRT_STO_CONS_CONFIG").ToString()
        Return strVersao.Trim()
    End Function

#Region "ConfigSessionState"

    Public Function ConsultaConfigSessionState() As String

        Try
            Dim stringConexao As String = Conn(RetornaNomeCliente(), HVDBs.DBVisionCorp)

            Dim strRetorno As String = String.Empty

            Dim cfg As String = SqlHelper.ExecuteScalar(stringConexao, "VSN_STO_CONS_CONFIG_SESS_STATE").ToString()

            If cfg.ToLower().Trim() = "inproc" Then

                strRetorno = "InProc"

            Else

                strRetorno = "SQLServer"

            End If

            Return strRetorno

        Catch ex As Exception

            Throw New Exception(ex.Message, ex)

        End Try

    End Function

#End Region

    ''' <summary>
    ''' Método responsável por retornar o link de uma chamada externa
    ''' </summary>
    ''' <param name="sessNomCli"></param>
    ''' <param name="site"></param>
    ''' <returns></returns>
    ''' <remarks>Gabriel Brito 08/10/13</remarks>
    Public Function RetornaLinkChamadaExterna(ByVal sessNomCli As String, ByVal site As String) As String
        Try
            Dim stringConexao As String = Conn(sessNomCli, HVDBs.DBVisionCorp)
            Dim ds As DataSet
            Dim sqlParam As New SqlClient.SqlParameter("@NOM_SITE", SqlDbType.VarChar)
            Dim http As String = "http://"
            Dim host As String = String.Empty
            Dim url As String = String.Empty
            Dim link As String = String.Empty

            sqlParam.Value = site
            ds = SqlHelper.ExecuteDataset(stringConexao, CommandType.StoredProcedure, "PRT_STO_CONS_LINK", sqlParam)

            If ds.Tables.Count > 0 AndAlso ds.Tables(0).Rows.Count > 0 Then
                Dim docXML As New XmlDocument
                Dim strArquivo As String = System.Configuration.ConfigurationManager.AppSettings.Item("PathConfig").ToString
                Dim ndXML As XmlNode
                docXML.Load(strArquivo)
                ndXML = docXML.SelectSingleNode("config/https")

                If ndXML Is Nothing Then
                    Throw New Exception("Falta configuração de https.")
                Else
                    If ndXML.InnerXml = "1" Then
                        http = "https://"
                    End If
                End If

                ndXML = docXML.SelectSingleNode("config/host")

                If ndXML Is Nothing Then
                    host = HttpContext.Current.Request.Url.Host
                Else
                    host = ndXML.InnerXml
                End If

                url = ds.Tables(0).Rows(0)("URL_INDEX").ToString()

                url = url.Substring(0, url.IndexOf("/"))

                link = http & host & "/" & url
            Else
                Throw New Exception("Configuração para o Site " & site & " não encontrada na tabela DBHV0000.VSN_CFG_SITE")
            End If

            Return link
        Catch ex As Exception
            Throw New Exception("Erro tentar recuperar link da chamada externa - " & ex.Message)
        End Try
    End Function

End Class
